//
//  HomeModel.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/7.
//  Copyright © 2017年 tml. All rights reserved.
//

import Foundation
import SwiftyJSON

//首页推荐数据模型 --------------------------

struct RecommentModel {
    var editTime: Int = 0
    var textItems: [Any]?
    var comicLists = [ComicListsModel]()
    var galleryItems = [GalleryItemModel]()
    init(jsonData: JSON) {
        editTime = jsonData["editTime"].intValue
        textItems = jsonData["textItems"].arrayValue

        if let gallery = jsonData["galleryItems"].arrayObject {
            for item in gallery {
                let json = JSON(item)
                let galleryItemModel = GalleryItemModel(jsonData: json)
                galleryItems.append(galleryItemModel)
            }
        }
        
        if let comiclists = jsonData["comicLists"].arrayObject {
            for item in comiclists {
                let json = JSON(item)
                let comiclistsModel = ComicListsModel(jsonData: json)
                comicLists.append(comiclistsModel)
            }
        }
    }
}

//banner数据模型
struct GalleryItemModel {
    var content: String?
    var cover: String?
    var title: String?
    var id: Int = 0
    var linkType: Int = 0
    var ext = [ExtModel]()
    init(jsonData: JSON) {
        content = jsonData["content"].stringValue
        cover = jsonData["cover"].stringValue
        title = jsonData["title"].stringValue
        id = jsonData["id"].intValue
        linkType = jsonData["linkType"].intValue
        if let extT = jsonData["ext"].arrayObject {
            for item in extT {
                let json = JSON(item)
                let extModel = ExtModel(jsonData: json)
                ext.append(extModel)
            }
        }
    }
}

struct ExtModel {
    var key: String?
    var val: String?
    init(jsonData: JSON) {
        key = jsonData["key"].stringValue
        val = jsonData["val"].stringValue
    }
}

//推荐内容数据模型
struct ComicListsModel {
    var comicType: Int = 0
    var argValue: Int = 0
    var newTitleIconUrl: String?
    var titleIconUrl: String?
    var description: String?
    var itemTitle: String?
    var argType: Int
    var argName: String?
    var sortId: Int = 0
    var canedit: Int = 0
    var comics = [ComicsModel]()
    init(jsonData: JSON) {
        comicType = jsonData["comicType"].intValue
        argValue = jsonData["argValue"].intValue
        newTitleIconUrl = jsonData["newTitleIconUrl"].stringValue
        titleIconUrl = jsonData["titleIconUrl"].stringValue
        description = jsonData["description"].description
        itemTitle = jsonData["itemTitle"].stringValue
        argType = jsonData["argType"].intValue
        argName = jsonData["argName"].stringValue
        sortId = jsonData["sortId"].intValue
        canedit = jsonData["canedit"].intValue
        if let comic = jsonData["comics"].arrayObject {
            for item in comic {
                let json = JSON(item)
                let comicsModel = ComicsModel(jsonData: json)
                comics.append(comicsModel)
            }
        }
    }
}

struct ComicsModel {
    var argName: String?
    var name: String?
    var itemTitle: String?
    var argValue: Int = 0
    var cover: String?
    var argCon: Int = 0
    var tags: [String]?
    var wideCover: String?
    var short_description: String?
    var is_vip: Int = 0
    var description: String?
    var cornerInfo: String?
    var author_name: String?
    var comicId: Int = 0
    var subTitle: String?
    var content: String?
    var title: String?
    var id: Int = 0
    var linkType: Int = 0
    var ext = [ExtModel]()
    init(jsonData: JSON) {
        argName = jsonData["argName"].string
        name = jsonData["name"].string
        itemTitle = jsonData["itemTitle"].string
        argValue = jsonData["argValue"].intValue
        cover = jsonData["cover"].stringValue
        argCon = jsonData["argCon"].intValue
        wideCover = jsonData["wideCover"].stringValue
        short_description = jsonData["short_description"].stringValue
        is_vip = jsonData["is_vip"].intValue
        description = jsonData["description"].stringValue
        cornerInfo = jsonData["cornerInfo"].stringValue
        author_name = jsonData["author_name"].stringValue
        comicId = jsonData["comicId"].intValue
        subTitle = jsonData["subTitle"].stringValue
        content = jsonData["content"].stringValue
        title = jsonData["title"].stringValue
        id = jsonData["id"].intValue
        tags = jsonData["tags"].arrayObject as? [String]
        linkType = jsonData["linkType"].intValue
        if let extT = jsonData["ext"].arrayObject {
            for item in extT {
                let json = JSON(item)
                let extModel = ExtModel(jsonData: json)
                ext.append(extModel)
            }
        }
    }
}

///===================

//////////首页排行数据模型
struct RankinglistModel {
    var rankinglist = [RankingModel]()
    init(jsonData: JSON) {
        if let rankList = jsonData["rankinglist"].arrayObject {
            for item in rankList {
                let json = JSON(item)
                let rankingModel = RankingModel(jsonData: json)
                rankinglist.append(rankingModel)
            }
        }
    }
}

struct RankingModel {
    var argName: String?
    var argCon: Int = 0
    var argValue: Int = 0
    var cover: String?
    var rankingType: String?
    var subTitle: String?
    var title: String?
    init(jsonData: JSON) {
        argName = jsonData["argName"].stringValue
        argValue = jsonData["argValue"].intValue
        cover = jsonData["cover"].stringValue
        rankingType = jsonData["rankingType"].stringValue
        subTitle = jsonData["subTitle"].stringValue
        title = jsonData["title"].stringValue
        argCon = jsonData["argCon"].intValue
    }
}

///////===

///////////首页订阅数据模型
struct SubscribeListModel {
    var newSubscribeList = [SubscribeComicListModel]()
    init(jsonData: JSON) {
        if let newSubscribe = jsonData["newSubscribeList"].arrayObject {
            for item in newSubscribe {
                let json = JSON(item)
                let model = SubscribeComicListModel(jsonData: json)
                newSubscribeList.append(model)
            }
        }
    }
}

struct SubscribeComicListModel {
    var argName: String?
    var argValue: Int = 0
    var canMore: Int = 0
    var description: String?
    var itemTitle: String?
    var maxSize: Int = 0
    var newTitleIconUrl: String?
    var titleIconUrl: String?
    var comics = [SubscribeComicsModel]()
    init(jsonData: JSON) {
        argName = jsonData["argName"].string
        argValue = jsonData["argValue"].intValue
        canMore = jsonData["canMore"].intValue
        description = jsonData["description"].stringValue
        itemTitle = jsonData["itemTitle"].stringValue
        newTitleIconUrl = jsonData["newTitleIconUrl"].stringValue
        titleIconUrl = jsonData["titleIconUrl"].string
        if let comic = jsonData["comics"].arrayObject {
            for item in comic {
                let json = JSON(item)
                let comicsModel = SubscribeComicsModel(jsonData: json)
                comics.append(comicsModel)
            }
        }
    }
}

struct SubscribeComicsModel {
    var comicId: Int = 0
    var cover: String?
    var name: String?
    var tags: [String]?
    init(jsonData:JSON) {
        comicId = jsonData["comicId"].intValue
        cover = jsonData["cover"].stringValue
        name = jsonData["name"].string
        tags = jsonData["tags"].arrayObject as? [String]
    }
}

/////////

//首页VIP数据模型
struct VIPListModel {
    var newVipList = [VIPComicsListModel]()
    init(jsonData: JSON) {
        if let newVIP  = jsonData["newVipList"].arrayObject {
            for item in newVIP {
                let json = JSON(item)
                let model = VIPComicsListModel(jsonData: json)
                newVipList.append(model)
            }
        }
    }
}

struct VIPComicsListModel {
    var argName: String?
    var argValue: Int = 0
    var canMore: Int = 0
    var description: String?
    var itemTitle: String?
    var maxSize: Int = 0
    var newTitleIconUrl: String?
    var titleIconUrl: String?
    var comics = [VIPComicsModel]()
    init(jsonData: JSON) {
        argName = jsonData["argName"].string
        argValue = jsonData["argValue"].intValue
        canMore = jsonData["canMore"].intValue
        description = jsonData["description"].stringValue
        itemTitle = jsonData["itemTitle"].stringValue
        newTitleIconUrl = jsonData["newTitleIconUrl"].stringValue
        titleIconUrl = jsonData["titleIconUrl"].string
        if let comic = jsonData["comics"].arrayObject {
            for item in comic {
                let json = JSON(item)
                let comicsModel = VIPComicsModel(jsonData: json)
                comics.append(comicsModel)
            }
        }
    }
}

struct VIPComicsModel {
    var comicId: Int = 0
    var cover: String?
    var name: String?
    var tags: [String]?
    init(jsonData:JSON) {
        comicId = jsonData["comicId"].intValue
        cover = jsonData["cover"].stringValue
        name = jsonData["name"].string
        tags = jsonData["tags"].arrayObject as? [String]
    }
}
////

//////////漫画列表数据模型（周榜，VIP榜，少年，玄幻等等） (⚠️多处共用 )


struct ComiscTypeListModel {
    var comics = [ComicsTypeModel]()
    var defaultParameters: DefaultParametersModel
    var hasMore: Bool?
    var page: Int = 1
    var spinnerList = [SpinnerListModel]()
    init(jsonData: JSON) {
        hasMore = jsonData["hasMore"].boolValue
        page = jsonData["page"].intValue
        defaultParameters = DefaultParametersModel(jsonData: jsonData["defaultParameters"])
        if let com = jsonData["comics"].arrayObject {
            for item in com {
                let json = JSON(item)
                let model = ComicsTypeModel(jsonData: json)
                comics.append(model)
            }
        }
    }
}

struct ComicsTypeModel {
    var author: String?
    var comicId: Int = 0
    var conTag: Int = 0
    var cover: String?
    var description: String?
    var flag: Int = 0
    var is_vip: Int = 0
    var name: String?
    var short_description: String?
    var tags:[String]?
    init(jsonData: JSON) {
        author = jsonData["author"].stringValue
        comicId = jsonData["comicId"].intValue
        conTag = jsonData["conTag"].intValue
        cover = jsonData["cover"].stringValue
        description = jsonData["description"].stringValue
        flag = jsonData["flag"].intValue
        is_vip = jsonData["is_vip"].intValue
        name = jsonData["name"].stringValue
        short_description = jsonData["short_description"].stringValue
        tags = jsonData["tags"].arrayObject as? [String]
    }
}

struct DefaultParametersModel {
    var defaultArgCon: Int = 0
    var defaultConTagType: String?
    var defaultSelection: Int = 0
    init(jsonData: JSON) {
        defaultArgCon = jsonData["defaultArgCon"].intValue
        defaultConTagType = jsonData["defaultConTagType"].stringValue
        defaultSelection = jsonData["defaultSelection"].intValue
    }
}

struct SpinnerListModel {
    var argCon: Int = 0
    var conTag: String?
    var name: String?
    init(jsonData: JSON) {
        argCon = jsonData["argCon"].intValue
        conTag = jsonData["conTag"].stringValue
        name = jsonData["name"].stringValue
    }
}
